package com.sensePlusVR.bean;

import java.io.Serializable;

import org.xutils.DbManager;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;
import org.xutils.ex.DbException;

import android.content.Context;

import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.utils.MyLog;
@Table(name = "CpuInfo")
public class CpuInfo implements Serializable{
	private static final String TAG = CpuInfo.class.getSimpleName();
	private static final long serialVersionUID = 1L;

	@Column(name = "id",isId = true,autoGen = false)
	private Integer id;

	@Column(name = "cpucode")
	private String cpucode;

	@Column(name = "cpualias")
	private String cpualias;

	@Column(name = "cpuname")
	private String cpuname;

	@Column(name = "gpu")
	private String gpu;

	@Column(name = "hwdecoder")
	private String hwdecoder;

	@Column(name = "softdecoder")
	private String softdecoder;

	@Column(name = "hwdecodertype")
	private String hwdecodertype;

	@Column(name = "unreal")
	private String unreal;

	@Column(name = "realvr")
	private String realvr;

	@Column(name = "real2d")
	private String real2d;

	@Column(name = "vendor")
	private String vendor;
	
	
	public Integer getId() {
		return id;
	}


	public void setId(Integer id) {
		this.id = id;
	}


	public String getCpucode() {
		return cpucode;
	}


	public void setCpucode(String cpucode) {
		this.cpucode = cpucode;
	}


	public String getCpualias() {
		return cpualias;
	}


	public void setCpualias(String cpualias) {
		this.cpualias = cpualias;
	}


	public String getCpuname() {
		return cpuname;
	}


	public void setCpuname(String cpuname) {
		this.cpuname = cpuname;
	}


	public String getGpu() {
		return gpu;
	}


	public void setGpu(String gpu) {
		this.gpu = gpu;
	}


	public String getHwdecoder() {
		return hwdecoder;
	}


	public void setHwdecoder(String hwdecoder) {
		this.hwdecoder = hwdecoder;
	}


	public String getSoftdecoder() {
		return softdecoder;
	}


	public void setSoftdecoder(String softdecoder) {
		this.softdecoder = softdecoder;
	}


	public String getHwdecodertype() {
		return hwdecodertype;
	}


	public void setHwdecodertype(String hwdecodertype) {
		this.hwdecodertype = hwdecodertype;
	}


	public String getUnreal() {
		return unreal;
	}


	public void setUnreal(String unreal) {
		this.unreal = unreal;
	}


	public String getRealvr() {
		return realvr;
	}


	public void setRealvr(String realvr) {
		this.realvr = realvr;
	}


	public String getReal2d() {
		return real2d;
	}


	public void setReal2d(String real2d) {
		this.real2d = real2d;
	}


	public String getVendor() {
		return vendor;
	}


	public void setVendor(String vendor) {
		this.vendor = vendor;
	}


	public static void saveOrUpdate(Object object) {
		try {
    		Context context = VRApplication.getAppContext();
    		if(context != null) {
    			DbManager db = VRApplication.getDbManager();
    			db.saveOrUpdate(object);
    		}
    	}catch(Exception e){
    		MyLog.e(TAG, "CPUInfo update failed: "+e);
    	}
	}
	
	
	public static CpuInfo getCPUInfo(){
		Context context = VRApplication.getAppContext();
		if(context != null){
			DbManager db = VRApplication.getDbManager();
			try {
				return db.findFirst(CpuInfo.class);
			} catch (DbException e) {
				MyLog.e(TAG, "getCPUInfo failed : " + e);
				return null;
			}
		}
		return null;
	}
	
	public static CpuInfo getCPUInfoByCpucode(String cpucode){
		
		Context context = VRApplication.getAppContext();
		if(context != null){
			DbManager db = VRApplication.getDbManager();
			try {
				return db.selector(CpuInfo.class).where("cpucode", "=", cpucode).findFirst();
			} catch (Exception e) {
				MyLog.e(TAG, "getCPUInfoByCpucode failed : " + e);
				return null;
			}
		}
		return null;
	}


	@Override
	public String toString() {
		return "CpuInfo [id=" + id + ", cpucode=" + cpucode + ", cpualias=" + cpualias + ", cpuname=" + cpuname
				+ ", gpu=" + gpu + ", hwdecoder=" + hwdecoder + ", softdecoder=" + softdecoder + ", hwdecodertype="
				+ hwdecodertype + ", unreal=" + unreal + ", realvr=" + realvr + ", real2d=" + real2d + ", vendor="
				+ vendor + "]";
	}

}
